﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class QuanTri_TrangDanhSachHS : System.Web.UI.Page
{
    SoLienLacDataContext db = new SoLienLacDataContext();
    clsLoadCombobox cls = new clsLoadCombobox();
    string manam;
    string malop;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Username"] == null || Session["Username"].ToString() == "")
        {
            Response.Redirect("~/GiaoDienClient/TrangChu.aspx");
        }
        else
        {
            manam = Request.QueryString["MaNam"];
            malop = Request.QueryString["MaLop"];
            if (!IsPostBack)
            {
                cls.LoadComboboxNamHoc(drNamHoc);
                cls.LoadComboboxLopHoc(drLopHoc, int.Parse(drNamHoc.SelectedValue.ToString()));

                if (manam != "" || manam != null)
                {
                    drNamHoc.SelectedValue = manam;
                    if (malop != "" || malop != null)
                    {
                        drLopHoc.SelectedValue = malop;

                    }
                }
                LoadGridHS(int.Parse(drNamHoc.SelectedValue.ToString()), int.Parse(drLopHoc.SelectedValue.ToString()));
                LoadGridPH(int.Parse(drNamHoc.SelectedValue.ToString()), int.Parse(drLopHoc.SelectedValue.ToString()));
            }
        }
    }
    private void LoadGridHS(int manam, int malop)
    {
        var c = from p in db.Lop_HocSinhs
                where p.MaNam == manam && p.MaLop == malop
                select new { p.MaHS, p.HocSinh.TenHS };
        grvDSHS.DataSource = c;
        grvDSHS.DataBind();
    }
    private void LoadGridPH(int manam, int malop)
    {
        var c = from p in db.Lop_HocSinhs
                where p.MaNam == manam && p.MaLop == malop
                select new { p.MaHS, p.HocSinh.TenHS,p.HocSinh.HoTenCha,p.HocSinh.HoTenMe,p.HocSinh.DiaChiCha,p.HocSinh.DiaChiMe,p.HocSinh.Email,p.HocSinh.SDT };
        grvDSPhuHuynh.DataSource = c;
        grvDSPhuHuynh.DataBind();
    }
    protected void drLopHoc_SelectedIndexChanged(object sender, EventArgs e)
    {
        int manam = int.Parse(drNamHoc.SelectedValue.ToString());
        int malop = int.Parse(drLopHoc.SelectedValue.ToString());
        LoadGridHS(manam, malop);
        LoadGridPH(manam, malop);
    }
    protected void lbkKetQuaTheoKy_Click(object sender, EventArgs e)
    {
        Response.Redirect("TrangKetQuaHocTapTheoKy.aspx?MaNam="+this.drNamHoc.SelectedValue.ToString()+"&MaLop="+this.drLopHoc.SelectedValue.ToString());
    }
    protected void lbkDanhGiaHK_Click(object sender, EventArgs e)
    {
        Response.Redirect("TrangDanhGiaHanhKiem.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
    protected void lbkTongHop_Click(object sender, EventArgs e)
    {
        Response.Redirect("TrangBangTongHopKetQua.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
    protected void imbKQTheoKy_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("TrangKetQuaHocTapTheoKy.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
    protected void imbDGHK_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("TrangDanhGiaHanhKiem.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("TrangBangTongHopKetQua.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
    protected void lbkTheoKy2_Click(object sender, EventArgs e)
    {
        Response.Redirect("TrangKetQuaHocTapTheoKy.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
    protected void imbTheoKy2_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("TrangKetQuaHocTapTheoKy.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
    protected void lbkHanhKiem2_Click(object sender, EventArgs e)
    {
        Response.Redirect("TrangDanhGiaHanhKiem.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
    protected void imbHanhKiem2_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("TrangDanhGiaHanhKiem.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
    protected void lbkTongHop2_Click(object sender, EventArgs e)
    {
        Response.Redirect("TrangBangTongHopKetQua.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
    protected void imbTongHop2_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("TrangBangTongHopKetQua.aspx?MaNam=" + this.drNamHoc.SelectedValue.ToString() + "&MaLop=" + this.drLopHoc.SelectedValue.ToString());
    }
}